<template>
  <div>
      <el-skeleton style="height: 50vh" :rows="4" :loading="loading" animated>
        <el-table
          :data="tableData"
          style="width: 100%"
          v-loading="loading"
          :header-cell-style="{
            background: '#F7F9FD',
            color: '#000',
            height: '48px',
            borderTop: '1px soild #E4E8F2'
          }"
        >
          <template #empty>
            <el-empty :image-size="150" description="暂无数据"></el-empty>
          </template>

          <el-table-column type="index" label="序号" width="80">
            <template v-slot="scope">
              <span>{{
                (pageState.pageNum - 1) * pageState.pageSize + scope.$index + 1
              }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="insMethod" label="检查方法">
          </el-table-column>
          <el-table-column label="是否合格">
            <template #default="{ row }">
              <span v-if='row.isQualifiedRec == 1'>合格</span>
              <span v-if='row.isQualifiedRec == 0'>不合格</span>
            </template>
          </el-table-column>
          <el-table-column prop="curHandleTime" label="验收时间">
          </el-table-column>
          <el-table-column label="状态">
            <template #default="{ row }">
              <span v-if='row.approveStatus == 1'>处理中</span>
              <span v-if='row.approveStatus == 2'>已完成</span>
            </template>
          </el-table-column>
          <el-table-column prop="partybHandlerName" label="处理人"></el-table-column>
          <el-table-column fixed="right" label="操作">
            <template #default="{ row }">
              <el-button
                type="text"
                size="small"
                @click="handleLook(row)"
                v-if='row.approveStatus == 2'
                >历史</el-button
              >
              <el-button
                type="text"
                size="small"
                @click="handleLook(row)"
                v-if='row.approveStatus == 1'
                >详情</el-button
              >
            </template>
          </el-table-column>
        </el-table>
        <re-pagination
          v-if="total > 0"
          :total="total"
          v-model:page="pageState.pageNum"
          v-model:limit="pageState.pageSize"
          @pagination="handleChangePage"
        />
      </el-skeleton>
  </div>
</template>
<script lang="ts">
import { defineComponent, ref,toRef} from "vue";
import {checkRecordList} from "/@/api/construction";
export default defineComponent({
  name: "checkList",
  props: {
    checkItem:{
      type: Object,
      default: () => {}
    }
  },
  emits: ["closeList"],
  setup(props, { emit }) {
    const tableData = ref([])
    const loading = ref<boolean>(false);
    const checkItemProp = toRef(props, "checkItem");
    const pageState = {
      pageNum: 1,
      pageSize: 10,
      checkItemId:checkItemProp.value?.id
    };
    //获取检查列表
    const getCheckRecordList = async () => {
      try {
        loading.value = true;
        const { code, data } = await checkRecordList(pageState);
        if (code === 200) {
          tableData.value = data.list;
        }
      } catch (err) {
        console.log(err);
      } finally {
        loading.value = false;
      }
    };
    const handleLook = async(row) => {
      const instanceId = row.instanceId
      emit("closeList",instanceId);
    };

    const handleChangePage = () => {
      getCheckRecordList();
    };

    getCheckRecordList()
    return {
      tableData,
      loading,
      pageState,
      handleLook,
      getCheckRecordList,
      handleChangePage
    };
  }
});
</script>
<style lang="scss" scoped>
  :deep .el-dialog__body {
    padding: 16px;
  }
  :deep .el-table{
    border: none;
  }
</style>
